package com.sd.reader;

import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Vector;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.alex.books.BaseBook;
import com.alex.books.BookMark;
import com.alex.books.BookPageFactory;
import com.alex.books.BookStore;
import com.alex.database.BookDao;
import com.alex.http.AGetReuqest;
import com.alex.http.AHandledResult;
import com.alex.http.AHttpEngine;
import com.alex.http.AHttpListener;
import com.alex.log.ALog;
import com.mobclick.android.MobclickAgent;
import com.sd.activity.BookInfoActivity;
import com.sd.activity.MainTabActivity;
import com.sd.activity.ReadBookActivity;
import com.sd.activity.ReadSetActivity;
import com.sd.activity.r.R;
import com.sd.util.DownloaderBookHandleable;
import com.sd.util.LoadingProgressDialog;
import com.sd.util.ReadUtil;
import com.sd.view.DialogManager;
import com.sd.view.ToastManager;

public class ReaderPopWindow implements OnClickListener,
		OnCheckedChangeListener, android.content.DialogInterface.OnClickListener {

	private long REQUEST_DOWNLOADBOOK = 0x03;
	/**
	 * 阅读模式
	 */
	private ImageButton mReadModelBT;
	/**
	 * 阅读设置
	 */
	private ImageButton mReadSetBT;
	/**
	 * 在线书城
	 */
	private ImageButton mOnlineBT;
	/**
	 * 书籍目录
	 */
	private ImageButton mBookContentsBT;
	/**
	 * 书籍信息
	 */
	private ImageButton mRelocationBT;
	/**
	 * 标题栏
	 */
	private TextView mTitleTV;
	/**
	 * 顶部操作区
	 */
	private RelativeLayout mTitleRL;
	/**
	 * 返回按钮
	 */
	private ImageButton mReturnBT;
	/**
	 * 增加书签按钮
	 */
	private ImageButton mBookMarkBT;
	private Button mOrder;
	
	private TextView mNumberTV;
	private LinearLayout mReadSetConLL;
	LinearLayout mBottomLL;
	RelativeLayout mReadsetRL;
	ReaderBook mReader;
	ReadBookActivity mContext;
	LayoutInflater mInflater;
	private ImageView mBookMark;
	/**
	 * 书本
	 */
	private BaseBook mBaseBook;
	private static ReaderPopWindow instance;

	public static ReaderPopWindow getInstance() {
		if (instance == null) {
			instance = new ReaderPopWindow();
		}
		return instance;
	}

	private PopupWindow pop;
	private float density;
	boolean isYe;

	private ReaderPopWindow(){
		
	}
	
	public PopupWindow createPopWindow(ReadBookActivity activity,
			ReaderBook reader) {

		int topBarHeight = 0;
		Class<?> c = null;
		Object obj = null;
		Field field = null;
		int x = 0;
		try {
			c = Class.forName("com.android.internal.R$dimen");
			obj = c.newInstance();
			field = c.getField("status_bar_height");
			x = Integer.parseInt(field.get(obj).toString());
			topBarHeight = activity.getResources().getDimensionPixelSize(x);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		mReader = reader;
		mContext = activity;
		DisplayMetrics metric = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(metric);
		density = metric.density; // 屏幕密度（0.75 / 1.0 / 1.5）
		mInflater = LayoutInflater.from(activity);
		View view = mInflater.inflate(R.layout.popwindow_reader, null);
		view.setPadding(0, topBarHeight, 0, 0);
		view.setId(0);
		view.setOnClickListener(mContext);
		mBottomLL = (LinearLayout) view
				.findViewById(R.id.bottom_operation);
		mReadsetRL = (RelativeLayout) view.findViewById(R.id.readsetrl);
		mTitleRL = (RelativeLayout) view.findViewById(R.id.title_operation);
		mTitleTV = (TextView) view.findViewById(R.id.title);
		mReturnBT = (ImageButton) view.findViewById(R.id.btn_return);
		mReturnBT.setOnClickListener(this);
		mBookMarkBT = (ImageButton) view.findViewById(R.id.btn_bookmark);
		mBookMarkBT.setOnClickListener(this);

		mReadModelBT = (ImageButton) view.findViewById(R.id.read_model_bt);
		mReadModelBT.setOnClickListener(this);
		mReadSetBT = (ImageButton) view.findViewById(R.id.read_set_bt);
		mReadSetBT.setOnClickListener(this);
		mOnlineBT = (ImageButton) view.findViewById(R.id.btn_online_city);
		mOnlineBT.setOnClickListener(this);
		mBookContentsBT = (ImageButton) view.findViewById(R.id.bookcontents_bt);
		mBookContentsBT.setOnClickListener(this);
		mRelocationBT = (ImageButton) view.findViewById(R.id.bookinfo_bt);
		mRelocationBT.setOnClickListener(this);
		
		mNumberTV = (TextView)view.findViewById(R.id.number);
		mNumberTV.setVisibility(View.GONE);
		
		mOrder = (Button)view.findViewById(R.id.order);
		mOrder.setOnClickListener(this);
		
		mBookMark = (ImageView)view.findViewById(R.id.bookmark);
		pop = new PopupWindow(view, metric.widthPixels, metric.heightPixels);
		isYe = ReaderSet.getInstance().getReadModel();
		changeReadModel();
		return pop;
	}
	
	private long mMark_id;
	public PopupWindow getpop(){
		Vector<BookMark> marks  = mBaseBook.mBookMarks;
		Vector<String> lines = BookPageFactory.getInstance().getLines();
		StringBuffer sbuf = new StringBuffer();
		for(int i=0;i<lines.size();i++){
			sbuf.append(lines.get(i));
		}
		int length = sbuf.length();
		mBookMark.setVisibility(View.GONE);
		for(int i=0;i<marks.size();i++){
			BookMark mark = marks.get(i);
			if(mark.mMarkPos >= mBaseBook.mReaderingInfo.mMarkPos && mark.mMarkPos <= mBaseBook.mReaderingInfo.mMarkPos + length){
				mMark_id = mark.id;
				mBookMark.setVisibility(View.VISIBLE);
				break;
			}
		}
		
		if(mBaseBook.mAttach2!=null && mBaseBook.mAttach2.equals("0")){
			mOrder.setVisibility(View.VISIBLE);
		}else{
			mOrder.setVisibility(View.GONE);
		}
		unVisibleReadSetLL();
		unVisibleReadRepositionLL();
		return pop;
	}
	
	public void setBaseBook( BaseBook baseBook){
		mBaseBook = baseBook;
		mTitleTV.setText(mBaseBook.mBookName);
	}

	public void dimss() {
		isReadSetVisible = false;
		if (pop != null && pop.isShowing()) {
			pop.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.order:
			DialogManager.getInstance().createOrder(mContext, this);
			break;
		case R.id.btn_return:
			mContext.finish();
			break;
		case R.id.btn_bookmark:
			MobclickAgent.onEvent(mContext, "readset","btn_bookmark");
			if(mBookMark.getVisibility() == View.VISIBLE){
				ToastManager.getInstance().showText(mContext, R.string.msg_success_delete_mark);
				
				Vector<BookMark> marks = mBaseBook.mBookMarks;
				for(int i=0;i<marks.size();i++){
					if(marks.get(i).id == mMark_id){
						mBaseBook.mBookMarks.remove(i);
					}
				}
				
				mBookMark.setVisibility(View.GONE);
				BookDao.getInstance().deleteBookMarks(mContext, (int)mMark_id);
			}else{
				ToastManager.getInstance().showText(mContext, R.string.msg_success_mark);
				String text = mBaseBook.mReaderingInfo.mCurText;
				if(text != null && text.length()>20){
					text = text.substring(20);
				}
				
				mMark_id = BookStore.getInstance().addBookMark(mContext, mBaseBook,text);
				mBookMark.setVisibility(View.VISIBLE);
				mBaseBook.mBookMarks = BookStore.getInstance().getBookMarks(mContext, mBaseBook.mBookId);
			}
			

			break;
		case R.id.read_model_bt:
			MobclickAgent.onEvent(mContext, "readset","read_model_bt");
			changeReadModel();
			mReader.reFreshPage();
			break;
		case R.id.read_set_bt:
			MobclickAgent.onEvent(mContext, "readset","read_set_bt");
			// 弹出阅读设置
			if (isReadSetVisible) {
				unVisibleReadSetLL();
			} else {
				visibleReadSetLL();
			}
			break;
		case R.id.btn_online_city:
			MobclickAgent.onEvent(mContext, "readset","btn_online_city");
			mContext.finish();
			Intent intent = new Intent(mContext, MainTabActivity.class);
			mContext.startActivity(intent);
			break;
		case R.id.bookcontents_bt:
			MobclickAgent.onEvent(mContext, "readset","bookcontents_bt");
			// 进入书籍信息
			mContext.startActivity(BookInfoActivity.getBookContents(mContext,
					mBaseBook.mBookId));
			break;
		case R.id.bookinfo_bt:
			MobclickAgent.onEvent(mContext, "readset","bookinfo_bt");
			// 进度条
			if (isReadReposition) {
				unVisibleReadRepositionLL();
			} else {
				visibleReadRepositionLL();
			}
			break;
		case 0:
			
			pop.dismiss();
			mContext.getWindow().addFlags(
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
			mContext.getWindow().clearFlags(
					WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
			break;
		default:
			break;
		}
	}

	/**
	 * 显示位置
	 */
	private void visibleReadRepositionLL() {
		final Intent mIntent = new Intent();
		mReadsetRL.removeAllViews();
		mReadsetRL.setVisibility(View.VISIBLE);
		View view = (View) mInflater
				.inflate(R.layout.read_set_reposition, null);
		ImageView left = (ImageView) view.findViewById(R.id.imageLeft);
		left.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mIntent.putExtra(ReadBookActivity.BOOK_ID, mBaseBook.mBookId);
				mIntent.putExtra(ReadBookActivity.READINGINFO, ReadUtil
						.getReaderInfo2(mBaseBook, 10000, (int) (ReadUtil.getPadding(mBaseBook, 10000) + 1),-1));
				mContext.onNewIntent0(mIntent);
			}
		});
		ImageView right = (ImageView) view.findViewById(R.id.imageRight);
		right.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mIntent.putExtra(ReadBookActivity.BOOK_ID, mBaseBook.mBookId);
				mIntent.putExtra(ReadBookActivity.READINGINFO, ReadUtil
						.getReaderInfo2(mBaseBook, 10000, (int) (ReadUtil.getPadding(mBaseBook, 10000) + 1),1));
				mContext.onNewIntent0(mIntent);
			}
		});
		final SeekBar reposition = (SeekBar) view
				.findViewById(R.id.reposition_seek_bar);
		reposition.setMax(10000);
		reposition.setProgress((int) ReadUtil.getPadding(mBaseBook, 10000));
		reposition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				mIntent.putExtra(ReadBookActivity.BOOK_ID, mBaseBook.mBookId);
				mIntent.putExtra(ReadBookActivity.READINGINFO, ReadUtil
						.getReaderInfo(mBaseBook, 10000, seekBar.getProgress()));
				mContext.onNewIntent0(mIntent);
				mNumberTV.setVisibility(View.GONE);
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				mNumberTV.setVisibility(View.VISIBLE);
			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				float u = Float.valueOf(progress) / seekBar.getMax();
				ALog.d("progress:"+progress);
				DecimalFormat myformat = null; 
				myformat= (DecimalFormat)NumberFormat.getPercentInstance(); 
				myformat.applyPattern("0.00%"); //0表示加的小数点,00表示两位小数点，你用00试一下你就知道效果 
				//myformat.setMaximumFractionDigits(Integer.MAX_VALUE);//这个1的意识是保存结果到小数点后几位（精确度）
				Log.e("", "seekBar getThumbOffset:"+seekBar.getThumbOffset());
				mNumberTV.setText(myformat.format(u));
			}
		});
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		mReadsetRL.addView(view);
		isReadReposition = true;
	}
	
	

	/**
	 * 隐藏位置
	 */
	private void unVisibleReadRepositionLL() {
		mReadsetRL.removeAllViews();
		mReadsetRL.setVisibility(View.GONE);
		isReadReposition = false;
	}

	/**
	 * 显示阅读设置布局
	 */
	private void visibleReadSetLL() {
		isReadSetVisible = true;
		mReadsetRL.removeAllViews();
		mReadsetRL.setVisibility(View.VISIBLE);
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		View view = (View) mInflater.inflate(R.layout.read_set_view, null);
		mReadsetRL.addView(view, params);

		mReadSetConLL = (LinearLayout) view.findViewById(R.id.read_set_con);
		operationFontSzie();
		RadioGroup radioGroup = (RadioGroup) view
				.findViewById(R.id.readset_radiogroup);
		radioGroup.setOnCheckedChangeListener(this);

	}

	private boolean isReadSetVisible = false;
	private boolean isReadReposition = false;

	/**
	 * 隐藏阅读设置布局
	 */
	private void unVisibleReadSetLL() {
		isReadSetVisible = false;
		mReadsetRL.removeAllViews();
		mReadsetRL.setVisibility(View.GONE);
	}

	/**
	 * 设置监听
	 */
	private OnClickListener listerner = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			mReadSetConLL.removeAllViews();
			int v_id = v.getId();

		}
	};

	/**
	 * 调节字体
	 */
	private void operationFontSzie() {
		View view = (View) mInflater.inflate(R.layout.read_set_fontsize, null);
		ImageButton big = (ImageButton) view.findViewById(R.id.fontsize_big);
		big.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ReaderSet.getInstance().getmFontSize() > 30) {
					ToastManager.getInstance().showText(mContext,
							R.string.msg_font_is_biggist);
				} else {
					ReaderSet.getInstance().increaseFontSize();
					mReader.setReaderTextSize(ReaderSet.getInstance()
							.getmFontSize(), density);
					mReader.reFreshPage();
				}
			}
		});

		ImageButton small = (ImageButton) view
				.findViewById(R.id.fontsize_small);
		small.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ReaderSet.getInstance().getmFontSize() < 16) {
					ToastManager.getInstance().showText(mContext,
							R.string.msg_font_is_smallist);
				} else {
					ReaderSet.getInstance().decreaseFontSize();
					mReader.setReaderTextSize(ReaderSet.getInstance()
							.getmFontSize(), density);
					mReader.reFreshPage();
				}

			}
		});
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		mReadSetConLL.addView(view);
	}

	/**
	 * 调节亮度
	 */
	private void operationBrightness() {
		LinearLayout view = (LinearLayout) mInflater.inflate(
				R.layout.read_set_brightness, null);
		SeekBar mSeekBar = (SeekBar) view
				.findViewById(R.id.brightness_seek_bar);
		mSeekBar.setProgress(ReaderSet.getInstance().getBrightness());
		mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				if (progress < 10) {
				} else {
					WindowManager.LayoutParams lp = mContext.getWindow()
							.getAttributes();
					lp.screenBrightness = Float.valueOf(progress) * (1f / 255f);
					mContext.getWindow().setAttributes(lp);
					ReaderSet.getInstance().setBrightness(progress);
				}
			}
		});
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		mReadSetConLL.addView(view);
	}

	/**
	 * 调节背景
	 */
	private void operationBackgrand() {
		int readbg0 = ReaderSet.getInstance().getReadBg();
		View view = (View) mInflater.inflate(R.layout.read_set_backgrand, null);
		final LinearLayout bglist = (LinearLayout) view.findViewById(R.id.bglist);

		Vector<ReadAttribute> readbg = ReaderConfig.READBG_MAP;

		for (int i = 0; i < readbg.size(); i++) {
			ImageButton but = new ImageButton(mContext);
			but.setPadding(10, 0, 10, 0);
			but.setImageResource((Integer) readbg.get(i).mKey);
			but.setBackgroundDrawable(null);
			but.setTag(readbg.get(i));
			if(readbg0 == (Integer) readbg.get(i).mValue){
				but.setSelected(true);
			}
			but.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					for(int i=0;i<bglist.getChildCount();i++){
						bglist.getChildAt(i).setSelected(false);
					}
					v.setSelected(true);
					ReadAttribute attribute = (ReadAttribute) v.getTag();

					mReader.setReaderBg((Integer) attribute.mValue,
							(Integer) attribute.mValue2);
					mReader.reFreshPage();
					ReaderSet.getInstance().setReadBg(
							(Integer) attribute.mValue);
					ReaderSet.getInstance().setFontColor(
							(Integer) attribute.mValue2);
				}
			});
			bglist.addView(but);
		}

		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		mReadSetConLL.addView(view);
	}

	/**
	 * 翻页模式
	 */
	private void operationMode() {
		View view = (View) mInflater.inflate(R.layout.read_set_mode, null);
		LinearLayout bglist = (LinearLayout) view.findViewById(R.id.readmode);

		Vector<ReadAttribute> readModes = ReaderConfig.READMODE;

		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params.leftMargin = 15;
		params.rightMargin = 15;
		params.weight = 1;
		for (int i = 0; i < readModes.size(); i++) {
			ReadAttribute read = readModes.get(i);
			Button but = new Button(mContext);
			but.setBackgroundResource(R.drawable.blue_bt_bg_);
			but.setText((String) read.mValue);
			int[][] state = { { android.R.attr.state_pressed },
					{ -android.R.attr.state_pressed } };
			int[] color = { mContext.getResources().getColor(R.color.white),
					mContext.getResources().getColor(R.color.grey) };
			ColorStateList colorStateList = new ColorStateList(state, color);
			but.setTextColor(colorStateList);
			but.setTag(read);
			but.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					ReadAttribute a = (ReadAttribute) v.getTag();
					mReader.setReaderDir(a.mKey);
					//mReader.reFreshPage();
					ReaderSet.getInstance().setReadmode(a.mKey);
				}
			});
			
			bglist.addView(but,params);
		}
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		mReadSetConLL.addView(view);
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		// TODO Auto-generated method stub
		mReadSetConLL.removeAllViews();
		switch (checkedId) {
		case R.id.operation_font_size:
			MobclickAgent.onEvent(mContext, "readset","operation_font_size");
			operationFontSzie();
			break;
		case R.id.operation_brightness:
			MobclickAgent.onEvent(mContext, "readset","operation_brightness");
			operationBrightness();
			break;
		case R.id.operation_backguard:
			MobclickAgent.onEvent(mContext, "readset","operation_backguard");
			operationBackgrand();
			break;
		case R.id.operation_mode:
			MobclickAgent.onEvent(mContext, "readset","operation_mode");
			operationMode();
			break;
		case R.id.operation_more:
			MobclickAgent.onEvent(mContext, "readset","operation_more");
			mContext.startActivity(ReadSetActivity.ReadBookTo(mContext,
					mBaseBook.mBookId));
			break;
		default:
			break;
		}
	}

	private void changeReadModel() {

		ReaderSet.getInstance().setReadModel(isYe);

		if (isYe) {
			// 夜间模式
			mReadModelBT.setImageResource(R.drawable.read_mode_ri);
			mReader.setReaderBg(R.drawable.wallpaper7, 0xffffffff);
			isYe = false;
		} else {
			// 普通模式
			mReadModelBT.setImageResource(R.drawable.read_mode_ye);
			mReader.setReaderBg(ReaderSet.getInstance().getReadBg(), ReaderSet
					.getInstance().getFontColor());
			isYe = true;
		}

	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		StringBuffer sbuf = new StringBuffer();
		/*sbuf.append("http://version.4gshu.com/version/?");
		sbuf.append("type=getBook");
		sbuf.append("&bid=");
		sbuf.append(mBaseBook.mBookSerial);
		sbuf.append("&cid=12345&uid=1234");*/
		LoadingProgressDialog.show(mContext, R.string.msg_downloading,oncancel);
		sbuf.append("http://version.4gshu.com/version?type=getBook&bid=");
		sbuf.append(mBaseBook.mBookSerial);
		sbuf.append("&cid=12345&uid=12345");
		
		AGetReuqest request = new AGetReuqest(REQUEST_DOWNLOADBOOK, sbuf.toString(), httpListener,new DownloaderBookHandleable(),null);
		AHttpEngine.getInstance().request(request);
		
/*		mBaseBook.mAttach2 = ""+1;
		BookDao.getInstance().updateBook(mContext, mBaseBook);
		mContext.finish();*/
	}
	
	AHttpListener httpListener =new AHttpListener() {
		
		@Override
		public void onResult(long requestId, Bundle paramBundle,
				AHandledResult paramHandledResult) {
			// TODO Auto-generated method stub
			LoadingProgressDialog.dismiss();
			if(requestId == REQUEST_DOWNLOADBOOK){
				ArrayList<String> list = (ArrayList<String>) paramHandledResult.mResults;
				String code = list.get(0);
				if(code.equals("0")){
					mBaseBook.mAttach2 = list.get(1);
					BookDao.getInstance().updateBook(mContext, mBaseBook);
					mContext.finish();
				}
				
			}
		}
		
		@Override
		public void onError(long requestId, Bundle paramBundle) {
			// TODO Auto-generated method stub
			ALog.e("onError");
			LoadingProgressDialog.dismiss();
			if(requestId == REQUEST_DOWNLOADBOOK){
				
			}
		}
	};

	OnCancelListener oncancel = new OnCancelListener() {
		
		@Override
		public void onCancel(DialogInterface dialog) {
			// TODO Auto-generated method stub
			LoadingProgressDialog.dismiss();
		}
	};
}
